package com.yvon.maple.service.auth.valicode.validate.code.processor;

import com.google.common.collect.Lists;
import com.yvon.maple.cloud.api.msg.feign.RemoteMsgClient;
import com.yvon.maple.cloud.api.msg.vo.SendMsgVo;
import com.yvon.maple.service.auth.valicode.validate.code.generator.CodeGenerator;
import com.yvon.maple.service.auth.valicode.validate.code.repository.CodeRepository;
import com.yvon.maple.service.auth.valicode.vo.CodeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author : Yvon
 * @since : 2022-01-27
 */
@Component(EmailCodeProcessor.PROCESSOR)
@Slf4j
public class EmailCodeProcessor extends AbstractCodeProcessor<CodeVo> {
    public static final String PROCESSOR = "emailCodeProcessor";

    public EmailCodeProcessor(Map<String, CodeGenerator> validateCodeGenerators, CodeRepository codeRepository) {
        super(validateCodeGenerators, codeRepository);
    }

    @Autowired
    private RemoteMsgClient remoteMsgClient;

    @Override
    protected void send(CodeVo validateCode) {
        SendMsgVo msgVo = new SendMsgVo();
        msgVo.setVariables(Lists.newArrayList(validateCode.getCode()));
        msgVo.setReceivers(Lists.newArrayList(validateCode.getKey()));
        msgVo.setType("login_email");
        remoteMsgClient.send(msgVo);
    }
}
